/**
 * Created by zhaojm on 15/3/21.
 */
// 熊
game.Bear = cc.Class.extend({
    _spriteSheet : null,
    _sprite : null,
    _action : null,

    _layer : null,
    _scale : null,

    ctor:function(){
        var size = cc.winSize;

        this._scale = 0;


        this._action = new cc.RepeatForever(new cc.Animate(
            new cc.Animation([0, 1, 2, 3, 4].map(function (i) {
                return cc.spriteFrameCache.getSpriteFrame("bear/" + i + ".png");
            }), 0.2)
        ));




        this._sprite = new cc.Sprite('#bear/0.png');
        this._sprite.setAnchorPoint(cc.p(0.5, 1));
        this._sprite.setPosition(cc.p(size.width * 0.51, size.height * 0.71));
        //this._sprite.retain();
        this._sprite.runAction(this._action);
        this._sprite.setScale(this._scale);

    },

    getCollidedHeight:function(){
        return this.getPositionY() - this.getHeight() * this._sprite.getScale() + 30;
    },

    addToLayer : function(layer, spriteSheet){
        this._layer = layer;
        this._spriteSheet = spriteSheet;
        this._spriteSheet.addChild(this._sprite);
        this._sprite.runAction(this._action);

    },

    getPositionY:function(){
        return this._sprite.y;
    },
    getPositionX:function(){
        return this._sprite.x;
    },

    getPosition:function(){
        return this._sprite.getPosition();
    },

    getHeight : function(){
        return this._sprite.getContentSize().height;
    },

    setScale:function(scale){
        if(this._layer._speedUpTimeCount>0){
            return;
        }
        if(scale <= 0){
            scale = 0;
        }else if(scale <= 0.3){
            scale = 0.3;
        }else if(scale >= 1){
            scale = 1;
            this._layer.gameOver();
        }else{

        }
        this._sprite.setScale(scale);
        //this._sprite.setScale(0);// test
    },
    getScale:function(){
        return this._sprite.getScale();
    },


    gameOver:function(){
        this._sprite.stopAllActions();
    },

    heroSpeedUp:function(){
        // 英雄加速，熊消失
        cc.log('hero speed up..');
        this._sprite.runAction(new cc.ScaleTo(0.3, 0));
    },


});